package com.Java.train.business.controller.daily;

import com.Java.train.business.entity.DailyTrain;
import com.Java.train.business.service.daily.DailyTrainCarriageService;
import com.Java.train.common.response.CommonResp;
import com.Java.train.business.entity.DTO.DailyTrainCarriageDTO;
import com.Java.train.business.req.daily.DailyTrainCarriageQueryReq;
import com.Java.train.common.response.PageResp;
import com.Java.train.business.entity.DailyTrainCarriage;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;

import java.util.Date;
import java.util.List;
/**
* @author luomoxingchen
* @since 2024-09-24
*/
@RestController
@RequestMapping("/admin/daily-train-carriage")
public class DailyTrainCarriageController {

    @Autowired
    private DailyTrainCarriageService dailyTrainCarriageService;


    @GetMapping("/query-list")
    @ApiOperation("DailyTrainCarriage查询全部")
    public CommonResp< PageResp<DailyTrainCarriageDTO>> queryList(@Valid DailyTrainCarriageQueryReq dailyTrainCarriageQueryReq){
        PageResp<DailyTrainCarriageDTO> list = dailyTrainCarriageService.queryList(dailyTrainCarriageQueryReq);
        return new CommonResp<>(list);
    }

    @PostMapping("/save")
    @ApiOperation("DailyTrainCarriage修改")
    public CommonResp<Object> update(@Valid @RequestBody DailyTrainCarriage dailyTrainCarriage) {
        return dailyTrainCarriageService.modify(dailyTrainCarriage);
    }


    @DeleteMapping(value = "/delete/{ids}")
    @ApiOperation("DailyTrainCarriage删除(单个条目)")
    public CommonResp<Object> remove(@NotBlank(message = "{required}") @PathVariable String ids) {
        return dailyTrainCarriageService.remove(ids);
    }

    @GetMapping("/gen-daily/{date}")
    public CommonResp<Object> genDaily(@PathVariable(value = "date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                                       String trainCode){
        dailyTrainCarriageService.genDaily(date, trainCode);
        return null;
    }
}
